package com.zbl.zblproject.erp.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zbl.zblproject.erp.entity.ErpFinanceLog;
import com.zbl.zblproject.erp.vo.ErpContractFinanceLogVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author youlanqiang
 * @version 1.0
 * @date 2018/12/11
 */
@Repository
public interface ErpFinanceLogMapper  extends BaseMapper<ErpFinanceLog> {

    @Select("SELECT * FROM zbl_finance_log WHERE order_sn = #{orderSn} order by id desc limit 0,1")
    ErpFinanceLog selectLogByOrderSn(@Param("orderSn") String orderSn);

    @Update("UPDATE zbl_finance_log SET status = #{status} WHERE order_sn = #{orderSn}")
    int updateLogStatusByOrderSn(@Param("orderSn") String orderSn, @Param("status") int status);

    @Select("SELECT status FROM zbl_finance_log WHERE order_sn = #{orderSn}")
    Integer selectStatusByOrderSn(@Param("orderSn") String orderSn);

    @Select("SELECT SUM(paid) FROM zbl_finance_log WHERE status = 2 AND store_name = #{supplierName} AND  checktime BETWEEN #{start} AND #{end} ")
    BigDecimal selectAllPriceBySupplierNameAndTime(@Param("supplierName") String supplierName,
                                                   @Param("start") LocalDateTime start, @Param("end") LocalDateTime end);
    List<ErpContractFinanceLogVo> selectFinance(@Param("start") String start,
                                                @Param("end")String end);
    @Select("SELECT order_sn,total,checktime FROM zbl_finance_log WHERE mode=0 AND store_name=#{userName}")
    List<ErpFinanceLog> selectByName(@Param("userName") String userName);

    @Update("update zbl_finance_log set context=#{context} where id=#{id}")
    int updateContext(@Param("id") int id,@Param("context")String context);
}
